package com.example.litehdfs.config;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 全局响应公共类
 * @author mading
 *
 */
public class ResponseMsg<T> implements Serializable{

  private static final long serialVersionUID = 1L;

  private int code;

  private String msg;

  private T data;

  @JsonIgnore
  public boolean isOk() {
    return CodeConstant.SUCCESS == code;
  }
  
  public int getCode() {
    return code;
  }

  public void setCode(int code) {
    this.code = code;
  }

  public String getMsg() {
    return msg;
  }

  public void setMsg(String msg) {
    this.msg = msg;
  }

  public T getdata() {
    return data;
  }
  
  public void setData(T data) {
    this.data = data;
  }

  public ResponseMsg(int code, String msg) {
    this.code = code;
    this.msg = msg;
  }
  
  public ResponseMsg(int code, String msg, T data) {
	  super();
	  this.code = code;
	  this.msg = msg;
	  this.data = data;
  }
  
  public ResponseMsg() {
  }

  /**
   * 返回成功信息
   *
   * @param data
   * @param <T>
   * @return
   */
  public static <T> ResponseMsg ofSuccess() {
	  return new ResponseMsg(CodeConstant.SUCCESS,"成功");
  }
  public static <T> ResponseMsg ofSuccess(T data) {
    return new ResponseMsg(CodeConstant.SUCCESS,"成功", data);
  }

  public static <T> ResponseMsg ofError(int code, T data) {
    return new ResponseMsg(code,"失败", data);
  }

  public static <T> ResponseMsg of(int code, String message, T data) {
    return new ResponseMsg(code, message, data);
  }

  /**
   * 返回成功信息
   *
   * @return
   */
  public static ResponseMsg of() {
    return new ResponseMsg(CodeConstant.SUCCESS, "成功");
  }


}
